The following example of an AppIcon custom handler was the simplest that I
could think of, (Sorry :) that might be semi-useful. What it does is put an
AppIcon on the Opus Desktop, any LhA archive that you drop onto this AppIcon
will be extracted to a directory of your choice.
NOTE: This script relies on the fact that your filetype ID for LhA archives
will be 'LHA'. If it isn't, then you will need to change the script
to suit your ID.
1/*
2$VER: LhAAppIcon.dopus5 1.0 (1.9.98)
3Call as: LhAAppIcon.dopus5 {Qp}
4*/
5options results
6parse arg port .
7
8lf = '0a'x
9LhAID = 'LHA' /* Change this line to suit your LhA filetype ID */
10iconname = 'DOpus5:Icons/filetypes/Archive' /* Change to use a different icon */
11output = 'RAM:'
12if port = '' then port = 'DOPUS.1'
13address value port
14
15If ~Show('L','rexxsupport.library') then call addlib('rexxsupport.library',0,-30,0)
16
17call openport('LhAAppIcon-handler')
18appmenu.count = 1
19appmenu.0 = 'Config'
20dopus addappicon 'LhAAppIcon-handler' "'LhAAppIcon'" 1 icon iconname info quotes close local menu appmenu.
21iconhandle = result
22flag = 0
23do while flag = 0
24 if waitpkt('LhAAppIcon-handler') then do
25 packet = getpkt('LhAAppIcon-handler')
26 arg0 = getarg(packet,0)
27 arg1 = getarg(packet,1)
28 arg2 = getarg(packet,2)
29 arg3 = getarg(packet,3)
30 arg4 = getarg(packet,4)
31 call reply(packet,0)
32 if arg0 = 'menu' & arg2 = 0 then call Config
33 if arg0 = 'info' then do
34 text = 'LhAAppIcon 1.0 (1.9.98)'||lf||lf||'G''day :)'
35 dopus request '"'text'" OK'
36 end
37 if arg0 = 'dropfrom' then call WeGotOne
38 if arg0 = 'close' then flag = 1
39 if arg0 = 'removed' then flag = 2
40 end
41end
42if flag~=2 then dopus remappicon iconhandle
43call closeport('LhAAppIcon-handler')
44exit
45
46Config:
47valid = 0
48do while valid = 0
49 text = '"Please enter a path to extract files to:" 30 "'output||'" OK|Cancel'
50 dopus getstring text
51 if dopusrc = 0 | result = '' then result = 'RAM:'
52 if pos(right(strip(result,,'"'),1),':/') > 0 then
53 if exists(result) then do
54 valid = 1
55 output = result
56 end
57end
58return
59
60WeGotOne:
61if arg2 = '' then return
62lister query arg3 path
63path = result
64dopus setappicon iconhandle busy on
65files = arg2
66do while files ~= ''
67 parse var files'"'file'"' files
68 file = strip(path,,'"')||strip(file,,'"')
69 dopus getfiletype '"'file'"' ID
70 if result = LhAID then
71 address command 'LhA >NIL: x "'file'" 'output
72end
73dopus setappicon iconhandle busy off
74return
Line:
1 - 4 The obligatory ARexx comment containing such useful information as
the script version and how to call it.
5 Enable ARexx results.
6 Parse the arguments for the Opus port name.
8 Set lf to the linefeed character.
9 Set LhAID to the filetype ID for LhA archives.
10 Set iconname to the path and filename of the icon that will appear
on the Desktop.
11 Set output to the default output path of RAM:
12 If they forgot to give us a port then we set it to the default port
'DOPUS.1'.
13 Address the Opus ARexx port.
15 If the rexxsupport.library isn't loaded, load it.
17 We open the message port for our handler, it's name will be
'LhAAppIcon-handler'.
18 - 19 We set up the stem variable that is going to be used for the AppIcon
popup menu. We set appmenu.count to the number of menuitems we will
have, in this case 1. Stem variables start counting from 0, so the
menuitem will be appmenu.0 which we have set to 'Config'.
20 The dopus addappicon command adds the AppIcon to the Desktop and
assigns the handler to it. It breaks down as follows:
dopus addappicon - The Opus ARexx command.
'LhAAppIcon-handler' - The name of the message port that we opened
earlier, any events that occur to the AppIcon
will send messages to this port.
"'LhAAppIcon'" - This is the label that will appear under the
icon.
1 - This is an ID for the icon, it will be
returned in messages sent to the handler.
icon iconname - This is telling Opus to use the icon imagery
that we set earlier in variable iconname, line
10.
info - The popup menu Information item will be
enabled.
quotes - All file arguments will be enclosed in quotes.
close - Display Close in the popup menu instead of the
normal Open.
local - The AppIcon will only appear on the Opus
Desktop and not the normal Workbench screen.
menu appmenu. - This tells Opus to add the menuitems found in
the stem variable appmenu., which we specified
earlier, to the AppIcon popup menu.
21 A handle will be returned, (much the same as opening a lister), which
we assign iconhandle to.
22 - 23 We set flag to 0, and enter a DO loop in which we cycle around until
flag doesn't equal 0.
24 This is where the script normally 'parks' while waiting for a message
packet. When we receive a packet, this if...then statement will
become true and the script will continue.
25 - 30 We get the message packet in a variable called packet and then get
the various arguments from it.
Arg0 - string identifying the event
Arg1 - ID specified in the addappicon command
Arg2 - filenames/menu ID/other information
Arg3 - source lister handle - if applicable
Arg4 - "icon" string identifying this as an "icon" event
31 Reply to the message packet, YOU MUST DO THIS!!!
32 If the event was 'menu' and the menuitem was 0 then call the Config
routine.
33 - 36 It was an 'info' event so we set text equal to some text and display
it in a requester.
37 Someone dropped something on our icon so we call the WeGotOne
routine.
38 The user picked 'Close' from the popup menu, so we set flag to 1.
The next time around the DO loop we will exit.
39 The event 'removed' means that Opus has quit, so we set flag to 2,
the next time around the DO loop we will exit.
40 End of the 'if waitpkt....'.
41 End of the 'do while....'.
42 We've exited the DO loop, either by quitting Opus or Closing our
AppIcon. If it was via the 'Close' menuitem then we issue a
dopus remappicon command to remove our AppIcon from the Desktop.
43 - 44 Close our message port and exit the script.
46 Sub-routine Config label.
47 - 48 Set valid to 0 and enter a DO loop until valid doesn't equal 0.
49 - 50 Set text to our display text and display it in a string requester.
51 If the user hit Cancel or entered no text then set it to the default
directory of RAM:.
52 Strip the quotes off the front and back of the string and see if it's
rightmost character is a ':' or a '/'.
53 - 56 If it was we check to see whether the path actually exists and if it
does set valid to 1 and output to our new directory.
57 End of the 'do while valid....' loop, we'll keep going around until
we get a valid directory from the user.
58 Return to the main handler loop.
60 Sub-routine WeGotOne label.
61 If Arg2 was empty, (no files), then we return immediately.
62 - 63 We ask for the path of the lister handle returned in Arg3, and set
path to it.
64 Set the AppIcon's state to busy, so it will become ghosted on the
Desktop and will ignore any more files dropped on it.
65 Set files to the list of files in Arg2.
66 Enter a DO loop while files is not empty.
67 Parse the first filename from files returning the rest of the string
back to files, for example:
files = "foo.lha" "bar.lha" "why.lha"
After: parse var files'"'file'"' files
file = "foo.lha"
files = "bar.lha" "why.lha"
68 Set file to the path and the filename without the leading and
trailing quotes.
69 Get the filetype ID of the file.
70 - 71 If the ID equals the ID for LhA archives that we set back in line 9,
then call the LhA archiver to extract the filename to the path set
in variable output.
72 Loop around to the next file.
73 All files are done, set the AppIcon state back to idle.
74 Return to the main handler loop.
As you can see, it isn't very hard. You could expand on this by adding
support for different archivers, saving the output directory in a config
file, etc.
To add a different archiver is very easy, for example let's add LZX
archives:
Find this line:
LhAID = 'LHA'
and add this after it:
LZXID = 'LZX' /* or whatever your filetype ID for LZX is */
then find this line:
address command 'LhA >NIL: x "'file'" 'output
and add these two after it:
if result = LZXID then
address command 'LZX >NIL: x "'file'" -d 'output
Done!
|